package org.dtrd.modules.record.entity.bean;

/**
 * @author qr
 * @date 2021/11/26 16:06
 */

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.dtrd.common.exception.JeecgBootException;
import org.dtrd.common.util.DateUtils;
import org.dtrd.modules.record.entity.po.DtrdEntRdSigninSuggest;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.dtrd.config.system.Constant.RecordType.*;

@ApiModel(value = "建议请求对象", description = "只有记录时间和患者 id 是必须的, 做获取请求时只需要传入 patientId 和 recordTime")
@Slf4j
@Getter
@Setter
public class SigninSuggestDailyInfo {

    @ApiModelProperty(value = "记录时间", required = true)
    private String recordTime;

    @ApiModelProperty(value = "患者id", required = true)
    private Integer patientId;

    @ApiModelProperty("血糖请求")
    private String bloodSugarSuggest;

    @ApiModelProperty("饮食请求")
    private String dietSuggest;

    @ApiModelProperty("运动请求")
    private String sportSuggest;

    @ApiModelProperty("用药请求")
    private String medicalSuggest;

    @ApiModelProperty("胰岛素请求")
    private String insulinSuggest;

    @ApiModelProperty("尿酮请求")
    private String ketoneSuggest;

    @ApiModelProperty("血压请求")
    private String bloodPressureSuggest;

    @ApiModelProperty("bmi请求")
    private String bmiSuggest;

    @ApiModelProperty("腰围请求")
    private String waistSuggest;

    @ApiModelProperty("睡眠请求")
    private String sleepSuggest;

    /**
     * 生成建议对象列表, 用于 batchSave
     * @return 建议对象列表
     */
    public List<DtrdEntRdSigninSuggest> toSuggestList(){
        // 目前就10个建议: 1-血糖，2-血压，3-运动，4-用药，5-饮食，6-体重，7-腰围，8-尿酮，9-胰岛素，10-睡眠
        ArrayList<DtrdEntRdSigninSuggest> poList = new ArrayList<>(10);
        // 血糖
        if (bloodSugarSuggest != null) {
            poList.add(buildSuggest(bloodSugarSuggest, SUGAR.getType()));
        }
        // 血压
        if (bloodPressureSuggest != null) {
            poList.add(buildSuggest(bloodPressureSuggest, BLOOD_PRESSURE.getType()));
        }
        // 运动
        if (sportSuggest != null) {
            poList.add(buildSuggest(sleepSuggest, SPORT.getType()));
        }
        // 用药
        if (medicalSuggest != null) {
            poList.add(buildSuggest(medicalSuggest, MEDICAL.getType()));
        }
        // 饮食
        if (dietSuggest != null) {
            poList.add(buildSuggest(dietSuggest, DIET.getType()));
        }
        // 体重
        if (bmiSuggest != null) {
            poList.add(buildSuggest(bmiSuggest, WEIGHT.getType()));
        }
        // 腰围
        if (waistSuggest != null) {
            poList.add(buildSuggest(waistSuggest, WAIST.getType()));
        }
        // 尿酮
        if (ketoneSuggest != null) {
            poList.add(buildSuggest(ketoneSuggest, KETONE.getType()));
        }
        // 胰岛素
        if (insulinSuggest != null) {
            poList.add(buildSuggest(insulinSuggest, INSULIN.getType()));
        }
        // 睡眠
        if (sleepSuggest != null) {
            poList.add(buildSuggest(sleepSuggest, SLEEP.getType()));
        }
        return poList;
    }

    private DtrdEntRdSigninSuggest buildSuggest(String suggestContent, Integer suggestType){
        DtrdEntRdSigninSuggest suggest = new DtrdEntRdSigninSuggest().init();
        suggest.setPatientId(this.getPatientId());
        try {
            Date date = DateUtils.parseDate(this.getRecordTime(), DateUtils.date_sdf.get().toPattern());
            suggest.setRecordTime(date);
        } catch (ParseException e) {
            String msg = "SigninSuggestDailyInfo.getBaseSuggestPo 日期转换失败: " + this.getRecordTime();
            log.error(msg);
            throw new JeecgBootException(msg);
        }
        suggest.setSuggestContent(suggestContent);
        suggest.setSigninType(suggestType);
        return suggest;
    }

}
